package gov.child.entities.po;

import gov.child.entities.vo.annotation.Alias;
import gov.child.entities.vo.annotation.IgnoreField;

import javax.persistence.*;
import java.util.Collection;

/**
 * @author fzh
 * @since 2017/9/16
 */
@Entity
@Table(name = "dept", schema = "gov_c")
public class EDepartment {
    @Alias("departmentId")
    private Integer id;
    private String deptCode;
    private String deptName;
    private String deptAddr;
    private String deptTel;
    private Integer deptParent;
    @IgnoreField
    private Collection<EAdmin> adminsById;
    @IgnoreField
    private Collection<EConsult> consultsById;
    @IgnoreField
    private Collection<EGuide> guidesById;
    @IgnoreField
    private Collection<EGuide> guidesById_0;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", nullable = false)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Basic
    @Column(name = "dept_code", nullable = false, length = 6)
    public String getDeptCode() {
        return deptCode;
    }

    public void setDeptCode(String deptCode) {
        this.deptCode = deptCode;
    }

    @Basic
    @Column(name = "dept_name", nullable = false, length = 32)
    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    @Basic
    @Column(name = "dept_addr", nullable = false, length = 60)
    public String getDeptAddr() {
        return deptAddr;
    }

    public void setDeptAddr(String deptAddr) {
        this.deptAddr = deptAddr;
    }

    @Basic
    @Column(name = "dept_tel", nullable = false, length = 13)
    public String getDeptTel() {
        return deptTel;
    }

    public void setDeptTel(String deptTel) {
        this.deptTel = deptTel;
    }

    @Basic
    @Column(name = "dept_parent", nullable = true)
    public Integer getDeptParent() {
        return deptParent;
    }

    public void setDeptParent(Integer deptParent) {
        this.deptParent = deptParent;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        EDepartment that = (EDepartment) o;

        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (deptCode != null ? !deptCode.equals(that.deptCode) : that.deptCode != null) return false;
        if (deptName != null ? !deptName.equals(that.deptName) : that.deptName != null) return false;
        if (deptAddr != null ? !deptAddr.equals(that.deptAddr) : that.deptAddr != null) return false;
        if (deptTel != null ? !deptTel.equals(that.deptTel) : that.deptTel != null) return false;
        if (deptParent != null ? !deptParent.equals(that.deptParent) : that.deptParent != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (deptCode != null ? deptCode.hashCode() : 0);
        result = 31 * result + (deptName != null ? deptName.hashCode() : 0);
        result = 31 * result + (deptAddr != null ? deptAddr.hashCode() : 0);
        result = 31 * result + (deptTel != null ? deptTel.hashCode() : 0);
        result = 31 * result + (deptParent != null ? deptParent.hashCode() : 0);
        return result;
    }

    @OneToMany(mappedBy = "deptByDeptId")
    public Collection<EAdmin> getAdminsById() {
        return adminsById;
    }

    public void setAdminsById(Collection<EAdmin> adminsById) {
        this.adminsById = adminsById;
    }

    @OneToMany(mappedBy = "deptByDeptId")
    public Collection<EConsult> getConsultsById() {
        return consultsById;
    }

    public void setConsultsById(Collection<EConsult> consultsById) {
        this.consultsById = consultsById;
    }

    @OneToMany(mappedBy = "deptByDeptP")
    public Collection<EGuide> getGuidesById() {
        return guidesById;
    }

    public void setGuidesById(Collection<EGuide> guidesById) {
        this.guidesById = guidesById;
    }

    @OneToMany(mappedBy = "deptByDeptC")
    public Collection<EGuide> getGuidesById_0() {
        return guidesById_0;
    }

    public void setGuidesById_0(Collection<EGuide> guidesById_0) {
        this.guidesById_0 = guidesById_0;
    }
}
